//品牌控制器
app.controller("brandController",function ($scope, $controller, brandService) {
    //继承自baseController中所有内容
    $controller("baseController",{$scope:$scope});
    //1.查询所有品牌列表
    $scope.findAll = ()=>{
        brandService.findAll().success(response =>{
            $scope.list = response;
        })
    }
    //2.分页查询所有品牌
    $scope.findByPage = (page,pagesize)=>{
        brandService.findByPage(page,pagesize).success(response =>{
            //将每页的记录数集合赋给list对象
            $scope.list = response.rows;
            //更新总记录数
            $scope.paginationConf.totalItems = response.total;
        })
    }
    //3.分页待条件查询品牌列表
    $scope.search = ()=>{
        brandService.search($scope.paginationConf.currentPage,$scope.paginationConf.itemsPerPage,$scope.searchEntity).
            success(response =>{
            //将每页的记录数集合赋给list对象
                $scope.list = response.rows;
            //更新总记录数
                $scope.paginationConf.totalItems = response.total;
        })
    }
    //4.显示修改界面内容
    $scope.updateUI = (brand)=>{
        $scope.entity = brand;
    }
    //6.保存品牌（添加或修改）
    $scope.save = ()=>{
        brandService.save($scope.entity).success(response =>{
            if (response.success){//如果添加或修改成功,就刷新页面
                $scope.search();
            } else {
                alert(response.message);
            }
        })
    }
    //7.根据选择的品牌id删除品牌
    $scope.dele = ()=>{
        brandService.dele($scope.selectIds).success(response =>{
            if (response.success){//如果删除成功,就刷新页面
                $scope.search();
            } else {
                alert(response.message)
            }
        })
    }
})